<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
    }

    .wrap {
        width: 500px;
        height: 500px;
        background-color: red;
        position: relative;
        /* flex布局 */
        /*  display: flex;
        justify-content: center;
        align-items: center; */
    }

    .inner {
        width: 200px;
        height: 200px;
        background-color: yellow;
        /* 使用该方式让块元素水平垂直居中，前提条件，元素有宽高 */
        /* position: absolute;
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
        margin: auto; */
        /* 第二种 */
        /*   position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%); */
        position: absolute;
        left: 50%;
        top: 50%;
        margin-left: -100px;
        margin-top: -100px;
    }
</style>

<body>
    <!-- 让块元素水平垂直居中 -->
    <div class="wrap">
        <div class="inner"></div>
    </div>
</body>

</html>